#include<windows.h>
int colin(POINT p1,POINT p2,POINT p3)
{
	float m1=100*(float)(p2.y-p1.y)/(p2.x-p1.x);
	float m2=100*(float)(p3.y-p2.y)/(p3.x-p2.x);
	float error=(m1 <= m2)? (m2-m1)/10 : (m1-m2)/10;
	if(error <= 0.195 || (p1.x==p2.x && p1.x==p3.x)|| (p1.y==p2.y &&p1.y==p3.y))
		return 1;
	return 0;
}

/*int inside(POINT *poligon,POINT punct)
{
	if(!poligon )
		return 0;
	int x,y,np,N=0;
	int i,j;
	POINT p;
	for(np=0;poligon[np].x!=0 || poligon[np].y!=0;np++)
	{}
	p.y=punct.y;
	for(i=0,j=i+1;i<np,j<np+1;i++,j++)
		for(x=punct.x;x<500;x++)
		{
			p.x=x;
			if(colin(p,poligon[i],poligon[j%(np)]))
				N++;
		}
	if(N%2)
		return 1;
	return 0;
}*/

int IsPolygon(POINT *p)
{
	if(!p)
		return -1;
	int i,j,k,l;
	for(j=0;j<4;j++)
		for(k=j+1;k<5;k++)
			for(l=k+1;l<6;l++)
			{	
				if(j==l%5)
					continue;
			if(((p[j].x==p[k].x && p[k].x==p[l%5].x) ||	//punctele care definesc poligonul nu trebuie sa fie colineare
			(p[j].y==p[k].y && p[k].y==p[l%5].y))&& 
			colin(p[j],p[k],p[l%5]) )
					return 0;
			}
	return 1;
}

int IsSimple(POINT *p)
{
	if(!p || !(IsPolygon(p)))
		return -1;
	POINT p1,p2,p3,p4;
	p1=p[0]; p2=p3=p[1]; p4=p[2];
	int i,j,k,l;
	/*for(i=0,j=i+1;i<,j<s-1;i++,j++)
		for(k=j,l=k+1;k<s-1,l<s;k++,l++)
		{
			for(int x0=min(p[i].x,p[j].x)+1;x0<max(p[i].x,p[j].x);x0++)
				for(int x=min(p[k].x,p[l].x)+1;x<max(p[k].x,p[l].x);x++)
					if(x0==x) 
					{
						for(int y0=min(p[i].y,p[j].y)+1;y0<max(p[i].y,p[j].y);y0++)
							for(int y=min(p[k].y,p[l].y)+1;y<max(p[k].y,p[l].y);y++)
								if(y0==y) 
									return 0;
					}
		}*/
	return 1;
}


//0.x,0.y=minime
//2.x,2.y=maxime

/*POINT* CreateRect(POINT *p)
{
	if(!p || !IsPolygon(p) || !IsSimple(p))
		return NULL;
	POINT Rect[4]={2000,2000,0,2000,0,0,2000,0};
	for(int i=0;i<5;i++)
	{
		if(p[i].x<Rect[0].x)
			Rect[0].x=Rect[3].x=p[i].x;
		if(p[i].x>Rect[1].x)
			Rect[1].x=Rect[2].x=p[i].x;
		if(p[i].y<Rect[0].y)
			Rect[0].y=Rect[1].y=p[i].y;
		if(p[i].y>Rect[2].y)
			Rect[2].y=Rect[3].y=p[i].y;
	}
	return Rect;*/
